/**
 * Copyright (c) 2010 CWI Amsterdam and others. All rights reserved.
 * This program and the accompanying materials are made available
 * under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *    CWI Amsterdam - initial API and implementation
 */
package nl.cwi.arne.generator.mcrl2;

import java.util.ArrayList;
import java.util.List;

import nl.cwi.arne.Network;
import nl.cwi.arne.Node;
import nl.cwi.arne.mcrl2.Atom;
import nl.cwi.arne.mcrl2.BasicTerm;
import nl.cwi.arne.mcrl2.Term;
import nl.cwi.arne.mcrl2.TupleType;
import nl.cwi.arne.mcrl2.Type;

/**
 * @author Christian Krause
 */
public class NetworkArguments {
	
	// The network:
	private Network network;
	
	// Level and delta arguments:
	private List<Atom> levels, deltas;
	
	/**
	 * Constructor.
	 */
	public NetworkArguments(Network network, List<Atom> container, Type levelType, Type deltaType) {
		this.network = network;
		levels = new ArrayList<Atom>();
		deltas = new ArrayList<Atom>();
		for (Node node : network.getNodes()) {
			levels.add(new Atom("c"+node.getName(), levelType));
		}
		for (Node node : network.getNodes()) {
			deltas.add(new Atom("d"+node.getName(), deltaType));
		}
		container.addAll(levels);
		container.addAll(deltas);
	}
	
	public Atom level(int index) {
		return levels.get(index);
	}

	public Atom level(Node node) {
		return levels.get(network.getNodes().indexOf(node));
	}

	public Atom delta(int index) {
		return deltas.get(index);
	}

	public Atom delta(Node node) {
		return deltas.get(network.getNodes().indexOf(node));
	}
	
	public TupleType type() {
		TupleType type = new TupleType();
		for (Atom level : levels) {
			type.getChildren().add(level.getType());
		}
		for (Atom delta : deltas) {
			type.getChildren().add(delta.getType());
		}
		return type;
	}
	
	public void makeTerms(List<Term> container) {
		for (int i=0; i<network.getNodes().size(); i++) {
			container.add(new BasicTerm(level(i)));
		}
		for (int i=0; i<network.getNodes().size(); i++) {
			container.add(new BasicTerm(delta(i)));
		}
	}
	
}
